package org.example.flyweight;

import java.util.HashMap;
import java.util.Map;

public class FlyweightFactory {
    private Map<Integer,Girl> pool = new HashMap<>();
    FlyweightFactory(){
        ChinaGirl chinaGirl1 = new ChinaGirl(1);
        ChinaGirl chinaGirl2 = new ChinaGirl(2);
        ChinaGirl chinaGirl3 = new ChinaGirl(3);
        pool.put(1,chinaGirl1);
        pool.put(2,chinaGirl2);
        pool.put(3,chinaGirl3);
    }

    public Girl getGirl(int uniqueKey){
        if(pool.containsKey(uniqueKey)){
            return pool.get(uniqueKey);
        }else{
            ChinaGirl chinaGirl = new ChinaGirl(uniqueKey);
            pool.put(uniqueKey,chinaGirl);
            return chinaGirl;
        }
    }
}
